// -----------------------------------------------------------------------------
// M A R I T I M E   R E S E A R C H   I N S T I T U T E   N E T H E R L A N D S
// -----------------------------------------------------------------------------
// Copyright (C) November 27, 2009 MARIN - All rights reserved - http://www.marin.nl
// -----------------------------------------------------------------------------
// Program  : mermaid
// Module   : vbm
// File     : Array2DTest.cpp
// -----------------------------------------------------------------------------

#include <gtest/gtest_prod.h>
#include "Array2D.h"

const double TOLERANCE = 0.000001;

TEST(Array2D, default_constructor)
{
    Array2D<int> array;
    EXPECT_EQ(0, array.m_Dim1);
    EXPECT_EQ(0, array.m_Dim2);
    EXPECT_EQ(0, array.m_Pitch);
    EXPECT_EQ(0, array.m_pElements);
    EXPECT_EQ(0, array.m_pPointers);
}

TEST(Array2D, size_constructor)
{
    Array2D<int> array(10, 20);
    EXPECT_EQ(10, array.m_Dim1);
    EXPECT_EQ(20, array.m_Dim2);
}


TEST(Array2D, copy_constructor)
{
    Array2D<int> array(10, 20);
    array[0][5] = 20;
    array[9][2] = 30;
    Array2D<int> array2(array);
    EXPECT_EQ(10, array2.dim1());
    EXPECT_EQ(20, array2.dim2());
    EXPECT_EQ(20, array2[0][5]);
    EXPECT_EQ(30, array2[9][2]);
}

TEST(Array2D, assignment_operator)
{
    Array2D<int> array(10, 20);
    array[0][5] = 20;
    array[9][2] = 30;
    Array2D<int> array2;
    array2 = array;
    EXPECT_EQ(10, array2.dim1());
    EXPECT_EQ(20, array2.dim2());
    EXPECT_EQ(20, array2[0][5]);
    EXPECT_EQ(30, array2[9][2]);
}

TEST(Array2D, no)
{
//    EXPECT_EQ(true, false);
}

TEST(Array2D, value_assignment)
{
    Array2D<int> array(10, 2);
    array = 20;
    EXPECT_EQ(20, array[3][1]);
}

TEST(Array2D, addition_operator)
{
    Array2D<int> array(10, 2);
    array = 20;
    array += 10;
    EXPECT_EQ(30, array[5][1]);
}

TEST(Array2D, multiplication_operator)
{
    Array2D<int> array(10, 2);
    array = 20;
    array *= 10;
    EXPECT_EQ(200, array[7][0]);
}

TEST(Array2D, equality_operator)
{
    Array2D<int> array(10, 2);
    array = 10;
    Array2D<int> array2(array);
    EXPECT_EQ(true, array2 == array);
}

TEST(Array2D, inequality_operator)
{
    Array2D<int> array(10, 2);
    array = 10;
    Array2D<int> array2(array);
    EXPECT_EQ(false, array2 != array);
}

TEST(Array2D, index_operator)
{
    Array2D<int> array(10, 2);
    array = 0;
    array[5][1] = 7;
    EXPECT_EQ(7, array(5,1));
}

TEST(Array2D, index_operator_alternative)
{
    Array2D<int> array(10, 2);
    array = 0;
    array(5,1) = 7;
    EXPECT_EQ(7, array[5][1]);
}

TEST(Array2D, index_operator_order)
{
    Array2D<int> array(10, 2);
    array = 0;
    array[5][1] = 7;
    array[5][2] = 8;
    int* p = array[5];
    EXPECT_EQ(7, p[1]);
    EXPECT_EQ(8, p[2]);
    ++p;
    EXPECT_EQ(7, *p);
    ++p;
    EXPECT_EQ(8, *p);
}

TEST(Array2D, dim1)
{
    Array2D<int> array(10, 5);
    ASSERT_EQ(10, array.dim1());
}

TEST(Array2D, dim2)
{
    Array2D<int> array(10, 5);
    ASSERT_EQ(5, array.dim2());
}

TEST(Array2D, clear)
{
    Array2D<int> array(10, 10);
    array = 10;
    array.clear();
    ASSERT_EQ(0, array[5][5]);
}

TEST(Array2D, resize)
{
    Array2D<int> array(10, 10);
    ASSERT_EQ(10, array.dim1());
    ASSERT_EQ(10, array.dim2());
    array.resize(5, 5);
    ASSERT_EQ(5, array.dim1());
    ASSERT_EQ(5, array.dim2());
}

TEST(Array2D, copy)
{
    Array2D<int> array(10, 10);
    array = 10;
    Array2D<int> array2(10, 10);
    array2 = 20;
    array2.copy(array);
    ASSERT_EQ(10, array2[6][4]);
}

